package com.jcbase.job;

import java.util.List;
import java.util.TimerTask;

import org.apache.log4j.Logger;

import com.jcbase.core.pojo.User;
import com.jcbase.core.util.AdUtil;
import com.jcbase.model.SysConfigAd;
import com.jcbase.model.SysGroup;

public class AdUserInJob extends TimerTask {
	
	private static Logger log  = Logger.getLogger(AdUserInJob.class);
	
    public AdUserInJob() {
	}


	@Override  
    public void run() {  
  
        log.info("开始添加AD用户");
        SysConfigAd sysConfigAd = SysConfigAd.dao.findFirst("Select * from sys_config_ad");
        if(sysConfigAd!=null){
        	String dc = sysConfigAd.getAdDc();
        	 AdUtil ad= new AdUtil();
         	if(ad.initLdap()){
         		List<User> userList = ad.GetADInfo(dc,ad.ctx );
             	SysGroup.me.insertUserGroup(userList);
       
             log.info("开始添加AD用户完成");
        }else{
          
        	  log.info("aldp登录失败，请检查配置");
        }
    }else{
    
    	  log.info("未找到AD配置，初始化失败");
    }
       
	}    

}
